/* halt.c
 *	Simple program to test whether running a user program works.
 *	
 *	Just do a "syscall" that shuts down the OS.
 *
 * 	NOTE: for some reason, user programs with global data structures 
 *	sometimes haven't worked in the Nachos environment.  So be careful
 *	out there!  One option is to allocate data structures as 
 * 	automatics within a procedure, but if you do this, you have to
 *	be careful to allocate a big enough stack to hold the automatics!
 */

#include "syscall.h"
int a[3];
int b, c;
int lock1;
int lock2;
int lock3;
int lock4;


int
main()
{
	Write("This is a test of the tests\n", 29, ConsoleOutput);
	
	lock1 = CreateLock("Lock1", 5);
	lock2 = CreateLock("Lock2", 5);
	lock3 = CreateLock("Lock3", 5);
	
	if (lock1 == 0)
		Write("Lock1 is index 0\n", 18, ConsoleOutput);
		
	if (lock2 == 1)
		Write("Lock2 is index 1\n", 18, ConsoleOutput);
		
	if (lock3 == 2)
		Write("Lock3 is index 2\n", 18, ConsoleOutput);
	
	DestroyLock(lock2);
	
	lock4 = CreateLock("Lock4", 5);
	
	if (lock4 == 3)
		Write("Lock4 is index 3\n", 18, ConsoleOutput);
	else if (lock4 == 1)
		Write("Lock4 is index 1\n", 18, ConsoleOutput);
		
	Acquire(lock1);
	Release(lock1);
	Release(lock3);
	
}
